(de functionalInterface (ClassName Function)
  (let (FirstArgument (thread Function car eval)
        Class (javaClass ClassName)
        FunctionalMethod (functionalMethodName Class) )
    (if (and
          (>= (javaVersion T) (1 7) )
          (catch+ '("Exception" "Error")
            (thread "java.lang.invoke.MethodHandle"
              javaClass
              (java "isInstance" FirstArgument)
              java) ) )
      (if (cdr Function)
        (apply methodHandleAsFunctionalInterface
          (append
            (list FirstArgument Class)
            (thread Function
              cdr
              (map+ mapcar eval) ) ) )
        (methodHandleAsFunctionalInterface
          FirstArgument Class) )
      (interface ClassName FunctionalMethod
        (cond
          ((and (thread Function cdr not)
                (thread FirstArgument fun?) )
            FirstArgument)
          ((fun? Function)
            Function)
          ((thread Function val cdr fun?)
            (thread Function val cdr) )
          (T
            (quit "Functional interface cannot be created with the given arguments"
              (list ClassName FunctionalMethod Function) ) ) ) ) ) ) )